/**
 * Created by BIYY on 2018-6-21.
 */
const path = require('path');
const autoprefixer = require('autoprefixer');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
//const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const project = require('../../build/project')

function resolve(dir) {
    return path.join(__dirname, '..', dir);
}

//@ngtools/webpack
module.exports = [
    /*{
        test: /\.ts?$/,
        loaders: project.environment === 'production' ? ['@ngtools/webpack'] : [
            'ts-loader', 'angular-router-loader', 'angular2-template-loader'],
        include: [resolve('../../src')],
        exclude: [/node_modules/]
    },*/
    {
        test: /\.html?$/,
        loader: 'raw-loader',
        include: [resolve('../../src')],
        exclude: [/node_modules/]
    },
    {
        test: /\.css/,
        use: ExtractTextPlugin.extract({
            fallback: 'style-loader',
            use: 'css-loader'
        }),

    },
    {
        test: /\.less$/,
        use: ExtractTextPlugin.extract({
            fallback: 'style-loader',
            use: [{
                loader: 'css-loader',
                options: {
                    minimize: true,
                    importLoaders: 1,
                    modules: true,
                    localIdentName: '[name]__[local]-[hash:base64:5]',
                    localIndexName: '[name]__[local]___[hash:base64:5]',
                }
            }, {
                loader: require.resolve('postcss-loader'),
                options: {
                    ident: 'postcss',
                    plugins: () => [
                        require('postcss-flexbugs-fixes'),
                        autoprefixer({
                            browsers: [
                                'last 10 versions',
                                'ie >= 6',
                                'ie_mob >= 6',
                                'ff >= 10',
                                'chrome >= 14',
                                'safari >= 3',
                                'ios >= 4',
                                'android >= 4.0'
                            ]
                        })
                    ],
                },
            },
                {
                    loader: require.resolve('less-loader'), // compiles Less to CSS
                }]
        })


    },
    {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: [/node_modules/],
        include: [resolve('../../src')]
    },
    {
        test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
        loader: 'url-loader',
        query: {
            limit: 10000,
            name: path.posix.join('static', 'img/[name].[ext]'),
        },
        exclude: [/node_modules/],
        include: [resolve('../../src')]
    },
    {
        test: /\.(woff|woff2?|eot|ttf|otf)(\?.*)?$/,
        loader: 'url-loader?limit=1000000',
        query: {
            limit: 1000,
            name: path.posix.join('static', 'fonts/[name].[ext]')
        },
        include: [resolve('../../src'), resolve('../../node_modules/element-ui')]
    },
    {
        test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
        loader: 'url-loader',
        options: {
            limit: 1000,
            name: path.posix.join('static', 'media/[name].[hash:7].[ext]')
        },
        exclude: [/node_modules/],
        include: [resolve('../../src')]
    }
];
